//
//  IMIBaseAppHelper.m
//  IMIFramework
//
//  Created by Travis on 09-8-10.
//  Copyright 2009 imi.im  All rights reserved.
//

#import "IMIBase/IMIBaseAppHelper.h"

@implementation UIApplication (IMIBase)
static UILabel *versionLabel=nil;
+ (void) showVersion{
#ifndef DEBUG
	return;
#endif
	//get current window
	NSArray *allWins=[[UIApplication sharedApplication] windows];
	UIWindow *window=[allWins objectAtIndex:[allWins count]-1];
	
	if(versionLabel!=nil){
		[window bringSubviewToFront:versionLabel];
		return;
	}
	
	NSDictionary *info=[[NSBundle mainBundle] infoDictionary];
	
	NSString *mainVersion=[info objectForKey:@"CFBundleVersion"];
	
	
	NSString *svnVersion=[info objectForKey:@"CFBundleShortVersionString"];
	if(svnVersion==nil || [svnVersion isEqualToString:@"exporte"]){
		svnVersion=@"0";
	}
	
	NSString *versionString=[NSString stringWithFormat:@"%@.%@",mainVersion,svnVersion];
	CGRect screenFrame=[[UIScreen mainScreen] applicationFrame];
	CGSize size=screenFrame.size;
	UIFont *font=[UIFont systemFontOfSize:12];
	CGSize tsize=[versionString sizeWithFont:font];
	
	versionLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, size.height-15, tsize.width, tsize.height)];
	versionLabel.text=versionString;
	versionLabel.font=font;
	versionLabel.textColor=[UIColor whiteColor];
	versionLabel.shadowColor=[UIColor blackColor];
	versionLabel.backgroundColor=[UIColor clearColor];
	
	[window addSubview:versionLabel];
	[versionLabel release];

}

+ (NSString*) appDir{
	return [[NSBundle mainBundle] resourcePath];
}
+ (NSString*) docDir{
	NSArray	*documentPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	return [documentPaths  objectAtIndex:0];
}
@end
